package com.herui.iot.ui.mime;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;

import com.herui.sdyu_lib.utils.StringUtils;
import com.herui.sdyu_lib.utils.ToastUtil;
import com.herui.sport_care.R;
import com.herui.sport_care.app.SportCareApp;
import com.herui.sport_care.data.user.UserInfo;
import com.herui.sport_care.ui.BaseSportActivity;
import com.herui.sport_care.ui.main.MainActivity;

import butterknife.OnClick;

public class WelcomeActivity extends BaseSportActivity {

    SportCareApp sportCareApp;

    UserPresenter userPresenter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        sportCareApp = SportCareApp.getInstance();

        userPresenter = new UserPresenter(new UserPresenter.UserView() {
            @Override
            public void verify(boolean flag) {
                if (flag){
                    jump(MainActivity.class);
                    finish();
                }else{
                    jump(LoginActivity.class);
                    finish();
                }
            }
        });
    }

    @Override
    public int getLayout() {
        return R.layout.activity_welcome;
    }

    @Override
    public void initParam() {
        if (sportCareApp.isEnterMain()){
            jump(MainActivity.class);
            finish();
        }
    }

    @OnClick({R.id.btn_start})
    public void onViewClick(View view) {
        UserInfo userInfo = userPresenter.getUserInfo();
        if (userInfo == null){
            jump(LoginActivity.class);
            finish();
        }else{
            userPresenter.verify();
        }
    }
}